package com.jic.data.service.impl;
import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.date.DateUtil;
import com.jic.data.model.vo.response.HistogramChartResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.jic.data.model.entity.DiscountRate;
import com.jic.data.mapper.SaleDiscountRateMapper;
import com.jic.data.service.SaleDiscountRateService;

import lombok.extern.slf4j.Slf4j;
/**
 * 接口实现类
 *
 * @author : 建投数据科技(山东)有限公司
 * @version : v1.0.0
 * @email :
 * @since : 2020-03-09 10:12:20
 */
@Service
@Slf4j
public class SaleDiscountRateServiceImpl implements SaleDiscountRateService {

	@Resource
	private SaleDiscountRateMapper mapper;




	/**
	 * 销售结构-折扣率趋势
	 *
	 * @param request 不分页查询入参实体类
	 * @return 数据库查到的实体类列表
	 */
	@Override
	public HistogramChartResponse listAllRecord(DiscountRate request) {
		List<DiscountRate> list =  mapper.selectBySelective(request);

		HistogramChartResponse response = new HistogramChartResponse();
		List<String> xDate = new ArrayList<>();
		List<Double> yMem = new ArrayList<>();
		List<Double> yTotal = new ArrayList<>();

		list.stream().forEach( category -> {
			xDate.add(DateUtil.format(category.getSaleDate(),"yyyy年MM"));
			yMem.add(category.getMemDiscountRate().doubleValue() / 1000000);
			yTotal.add(category.getTotalDiscountRate().doubleValue() / 1000000);
		});
		response.setX(xDate);
		response.setY1(yMem);
		response.setY2(yTotal);
		return response;
	}




}
